﻿using System;
using System.Windows;
using System.Windows.Controls;
using TheOliver.DigitalSignage.Client.Interfaces;

namespace CeBIT2010
{
    public partial class CebitSlidePlaceholder : UserControl, ISlidePlaceholder
    {
        public CebitSlidePlaceholder()
        {
            InitializeComponent();
        }

        #region ISlidePlaceholder Members

        public FrameworkElement Slide
        {
            get
            {
                return _content.Content as FrameworkElement;
            }
            set
            {
                _content.Content = value;
            }
        }

        public event EventHandler HideSlideCompleted;
        public event EventHandler ShowSlideCompleted;

        private void OnHideSlideCompleted()
        {
            if (HideSlideCompleted != null)
            {
                HideSlideCompleted(this, EventArgs.Empty);
            }
        }

        private void OnShowSlideCompleted()
        {
            if (ShowSlideCompleted != null)
            {
                ShowSlideCompleted(this, EventArgs.Empty);
            }
        }

        public void ShowSlide()
        {
            _showSlideStoryboard.Completed += _showSlideStoryboard_Completed;
            _showSlideStoryboard.Begin();
        }

        void _showSlideStoryboard_Completed(object sender, EventArgs e)
        {
            _showSlideStoryboard.Completed -= _showSlideStoryboard_Completed;
            OnShowSlideCompleted();
        }

        public void HideSlide()
        {
            _hideSlideStoryboard.Completed += _hideSlideStoryboard_Completed;
            _hideSlideStoryboard.Begin();
        }

        void _hideSlideStoryboard_Completed(object sender, EventArgs e)
        {
            _hideSlideStoryboard.Completed -= _hideSlideStoryboard_Completed;
            OnHideSlideCompleted();
        }

        #endregion
    }
}
